import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/Home/Home'


Vue.use(VueRouter)



const routes = [
  {
    path: '/singleLogin',
    name: 'singleLogin',
    component: () => import('../views/singleLogin/singleLogin'),
  },{
    path: '/login',
    name: 'login',
    component: () => import('../views/login/login'),
  },
  {
    path: '/',
    name: 'Main',
    component: ()=>import('../views/Main/Main'),
    children:[
      {
        path: '/searchPage/searchPage',
        name: 'searchPage',
        component: ()=>import('../views/searchPage/searchPage'),
      },
      {
        path: '/home',
        name: 'home',
        component: HomeView,
      },{
        path: '/columnManage/columnManage',
        name: 'columnManage',
        component: ()=>import('../views/columnManage/columnManage/columnManage'),
      },{
        path: '/columnManage/contentManage',
        name: 'contentManage',
        component: ()=>import('../views/columnManage/contentManage/contentManage'),
      },{
        path: '/columnManage/contentManageOut',
        name: 'contentManageOut',
        component: ()=>import('../views/columnManage/contentManageOut/contentManage'),
      },{
        path: '/message/messageTodo',
        name: 'messageTodo',
        component: ()=>import('../views/messageManage/message/message'),
      },{
        path: '/message/messageDone',
        name: 'messageDone',
        component: ()=>import('../views/messageManage/message/message'),
      },
      {
        path: '/message/messagePre',
        name: 'messagePre',
        component: ()=>import('../views/messageNotice/message/message'),
      },{
        path: '/message/messageRead',
        name: 'messageRead',
        component: ()=>import('../views/messageNotice/message/message'),
      },
      {
        path: '/systemManage/user',
        name: 'user',
        component: ()=>import('../views/systemManage/user/userT'),
      },{
        path: '/systemManage/role',
        name: 'role',
        component: ()=>import('../views/systemManage/role/roleT'),
      },{
        path: '/systemManage/org',
        name: 'org',
        component: ()=>import('../views/systemManage/org/orgT'),
      },{
        path: '/systemManage/log',
        name: 'log',
        component: ()=>import('../views/systemManage/log/logT'),
      },{
        path: '/systemManage/dict',
        name: 'dict',
        component: ()=>import('../views/systemManage/dict/dictT'),
      },{
        path: '/systemManage/applicationCenter',
        name: 'applicationCenter',
        component: ()=>import('../views/systemManage/applicationCenter/applicationCenter'),
      },{
        path: '/application/application',
        name: 'application',
        component: ()=>import('../views/application/application'),
      },{
        path: '/processHandling/audit',
        name: 'audit',
        component: ()=>import('../views/processHandling/audit/audit'),
      },{
        path: '/processHandling/audited',
        name: 'audited',
        component: ()=>import('../views/processHandling/audited/audited'),
      },{
        path: '/news/newsList',
        name: 'newsList',
        component: ()=>import('../views/news/newsList'),
      },{
        path: '/news/detail',
        name: 'detail',
        component: ()=>import('../views/news/detail.vue'),
      },{
        path: '/APImanage/APIapply',
        name: 'APIapply',
        component: ()=>import('../views/APImanage/APIapply/APIapply.vue'),
      },{
        path: '/APImanage/APIlist',
        name: 'APIlist',
        component: ()=>import('../views/APImanage/APIlist/APIlist.vue'),
      },{
        path: '/APImanage/APIsystem',
        name: 'APIsystem',
        component: ()=>import('../views/APImanage/APIsystem/APIsystem.vue'),
      },
    ]
  },

]
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location){
  return originalPush.call(this , location).catch(err=>err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location){
  return originalReplace.call(this , location).catch(err=>err)
}

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  if(to.path=='/'){
    next({name:'home'})
  }else{
    next()
  }

})


export default router
